import type { IProduct } from "@/utils/types";
import type { ProColumns } from "@ant-design/pro-components";
import {  Image, Popconfirm, Space } from "antd";

interface IProps {
  onEditHandler: (id: string) => void;
  onCardHandler: (id: string) => void;
  onDeleteHandler: (id: string) => void;
}

export const getColumns: ({
  onEditHandler,
  onCardHandler,
  onDeleteHandler,
}: IProps) => ProColumns<IProduct, "text">[] = ({
  onEditHandler,
  onCardHandler,
  onDeleteHandler,
}) => {
  return [
    {
      title: "#",
      dataIndex: "id",
      valueType: "indexBorder",
      search: false,
      // copyable: true,
      width: 50,
    },
    {
      title: "封面",
      dataIndex: "coverUrl",
      search: false,
      copyable: true,
      width: 100,
      render: (_, record: IProduct) => {
        return <Image src={record.coverUrl} />;
      },
    },
    {
      title: "商品名",
      dataIndex: "name",
      // key: "name",
      ellipsis: true,
      copyable: true,
      formItemProps: {
        rules: [{ required: true, message: "此项必填" }],
      },
    },
    {
      title: "原价",
      dataIndex: "orginalPrice",
      width: 50,
    },
    {
      title: "优惠价",
      dataIndex: "preferentialPrice",
      width: 80,
    },
    {
      title: "库存",
      dataIndex: "stock",
      width: 80,
      align: "center",
      search: false,
    },
    {
      title: "当前库存",
      dataIndex: "curStock",
      width: 80,
      align: "center",
      search: false,
    },
    {
      title: "每人限购",
      dataIndex: "limitBuyNumber",
      width: 80,
      align: "center",
      search: false,
    },
    {
      title: "销量",
      dataIndex: "buyNumber",
      width: 80,
      align: "center",
      search: false,
    },
    {
      title: "操作",
      dataIndex: "id",
      key: "id",
      valueType: "option",
      align: "center",
      width: 300,
      render: (_text, entity) => (
        <Space>
          <a
            key="edit"
            type="link"
            onClick={() => onEditHandler(entity.id)}
          >
            编辑
          </a>
          <a
            key="card"
            type="link"
            onClick={() => onCardHandler(entity.id)}
          >
            绑定消费卡
          </a>
          <Popconfirm
            title="提醒"
            description="确认要删除吗？"
            onConfirm={() => onDeleteHandler(entity.id)}
          >
            <a
              key="delete"
              type="link"
              style={{
                color:'red'
              }}
            >
              删除
            </a>
          </Popconfirm>
        </Space>
      ),
    },
  ];
};
